﻿/** \file
* \$Rev: 183 $
* 
* \$Date: 2010-04-14 00:34:38 +0000 (Wed, 14 Apr 2010) $
*
* \$URL: http://chorus-twitter.googlecode.com/svn/trunk/tests/src/TestSerializeUtils.cs $
*/

using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using chorus.utils;

namespace chorus.tests
{
	/// <summary>
	/// Test some of the serialization helper classes in chorus.utils.
	/// </summary>
	[TestClass]
	public class TestSerializeUtils
	{
		/// <summary>A utility class for testing SerDate serialization.</summary>
		public class datetime
		{
			/// <summary>The date object to test.</summary>
			public SerDate date;
		}

		/// <summary>Tests SerDate serialization with some sample XML.</summary>
		[TestMethod]
		public void SerDate()
		{
			XmlSerializer ser = new XmlSerializer(typeof(datetime));
			string xml =
				"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
				"<datetime><date>Mon Jun 15 14:09:02 -07:00 2009" +
				"</date></datetime>";
			StringReader reader = new StringReader(xml);
			datetime dt = (datetime)ser.Deserialize(reader);

			DateTime xdate = dt.date.Coalesce.ToUniversalTime(),
				compare = new DateTime(2009, 6, 15, 14 + 7, 9, 2);
			Assert.AreEqual(compare.CompareTo(xdate), 0);

			xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
				"<datetime><date></date></datetime>";
			reader = new StringReader(xml);
			dt = (datetime)ser.Deserialize(reader);
			Assert.IsNull(dt.date.val);
		}
	}
}
